package com.xiong.ai.exception;

import com.xiong.ai.result.ResBody;
import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @program: ai
 * @description:
 * @author: Mr.熊
 * @create: 2024-05-31 10:52
 **/
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler({Exception.class})
    public ResBody<Void> handleException(Exception exception) {
        ResBody<Void> resBody = new ResBody<>();
        resBody.setMsg("系统繁忙请稍后再试");
        if (exception instanceof BusinessException) {
            resBody.setMsg(exception.getMessage());
        }
        if (exception instanceof MaxUploadSizeExceededException) {
            resBody.setMsg("上传文件超过了大小限制");
        }
        if (exception instanceof FileSizeLimitExceededException) {
            resBody.setMsg("上传文件超过了大小限制");
        }
        return resBody;
    }
}
